package com.xhcl.web.controller.system;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TGgDlyhwh;
import com.xhcl.system.service.ITGgDlyhwhService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.domain.Ztree;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 代理银行Controller
 * 
 * @author xhcl
 * @date 2020-08-24
 */
@Controller
@RequestMapping("/system/dlyhwh")
public class TGgDlyhwhController extends BaseController
{
    private String prefix = "system/dlyhwh";

    @Autowired
    private ITGgDlyhwhService tGgDlyhwhService;

    @RequiresPermissions("system:dlyhwh:view")
    @GetMapping()
    public String dlyhwh()
    {
        return prefix + "/dlyhwh";
    }

    /**
     * 查询代理银行列表
     */
    @RequiresPermissions("system:dlyhwh:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGgDlyhwh tGgDlyhwh)
    {
        startPage();
        List<TGgDlyhwh> list = tGgDlyhwhService.selectTGgDlyhwhList(tGgDlyhwh);
        return getDataTable(list);
    }

    /**
     * 导出代理银行列表
     */
    @RequiresPermissions("system:dlyhwh:export")
    @Log(title = "代理银行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGgDlyhwh tGgDlyhwh)
    {
        List<TGgDlyhwh> list = tGgDlyhwhService.selectTGgDlyhwhList(tGgDlyhwh);
        ExcelUtil<TGgDlyhwh> util = new ExcelUtil<TGgDlyhwh>(TGgDlyhwh.class);
        return util.exportExcel(list, "dlyhwh");
    }

    /**
     * 新增代理银行
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理银行
     */
    @RequiresPermissions("system:dlyhwh:add")
    @Log(title = "代理银行", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGgDlyhwh tGgDlyhwh)
    {
        return toAjax(tGgDlyhwhService.insertTGgDlyhwh(tGgDlyhwh));
    }

    /**
     * 修改代理银行
     */
    @GetMapping("/edit/{yhbm}")
    public String edit(@PathVariable("yhbm") String yhbm, ModelMap mmap)
    {
        TGgDlyhwh tGgDlyhwh = tGgDlyhwhService.selectTGgDlyhwhById(yhbm);
        mmap.put("tGgDlyhwh", tGgDlyhwh);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理银行
     */
    @RequiresPermissions("system:dlyhwh:edit")
    @Log(title = "代理银行", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGgDlyhwh tGgDlyhwh)
    {
        return toAjax(tGgDlyhwhService.updateTGgDlyhwh(tGgDlyhwh));
    }

    /**
     * 删除代理银行
     */
    @RequiresPermissions("system:dlyhwh:remove")
    @Log(title = "代理银行", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGgDlyhwhService.deleteTGgDlyhwhByIds(ids));
    }
    

    /**
     * 选择代理银行树
     */
    @GetMapping(value = { "/selectDlyhwhTree/{yhbm}", "/selectDlyhwhTree/" })
    public String selectDlyhwhTree(@PathVariable(value = "yhbm", required = false) String yhbm, ModelMap mmap)
    {
        if (StringUtils.isNotEmpty(yhbm))
        {
            mmap.put("tGgDlyhwh", tGgDlyhwhService.selectTGgDlyhwhById(yhbm));
        }
        return prefix + "/tree";
    }

    /**
     * 加载代理银行树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData()
    {
        List<Stree> ztrees = tGgDlyhwhService.selectTGgDlyhwhTree();
        return ztrees;
    }
}
